# -*- coding: utf-8 -*-
"""
@Time ： 2022/12/27 0:20
@Auth ： jiraWu
@File ：get_代码示例.py
@IDE ：PyCharm
@Motto:人生苦短，我学Python

"""

"""
   get请求使用示例
   演示爬取豆瓣电影数据
"""

from jira_wu_dev_utils._request import GetRequest


def down_load_get(cont: str, page: int):
    with open(f'豆瓣电影\douban{page}.json', 'w', encoding='utf-8') as f:
        f.write(cont)
    print(f"第【{page}】页已经完成下载！")


if __name__ == '__main__':
    start_page = int(input("起始页码："))
    start_end = int(input("结束页码："))
    page = 1
    for start in range((start_page - 1) * 10, start_end * 10, 10):
        url = f"https://movie.douban.com/j/chart/top_list?type=5&interval_id=100%3A90&action=&"
        data = {
            'start': start,
            'limit': 20
        }
        # 发送代理请求
        # cont = GetRequest(url=url, data=data).proxy_req({'http': '127.0.0.1'})
        # 发送非代理请求
        cont = GetRequest(url=url, data=data).send_req()
        down_load_get(cont, page)
        page += 1
